package edu.hit.pact.pgse.timer;

import java.util.Calendar; 
import java.util.Date; 
/**
 * A DailyIterator class returns a sequence of dates on subsequent days
 * representing the same time each day.
 */ 
public class TimeCalculator {
    public static Date nextTime(int hourOfDay, int minute, int second) { 
    	Calendar calendar = Calendar.getInstance(); 
        //reset the hour, minute and second
        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); 
        calendar.set(Calendar.MINUTE, minute); 
        calendar.set(Calendar.SECOND, second); 
        calendar.set(Calendar.MILLISECOND, 0); 
        
    	Date now = new Date();
    	if (calendar.getTime().before(now)) { 
            calendar.add(Calendar.DATE, 1); 
        }
    	
        return calendar.getTime(); 
    }
    
    public static long nextDelayTime(int hourOfDay, int minute, int second) { 
    	Calendar calendar = Calendar.getInstance(); 
        //reset the hour, minute and second
        calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); 
        calendar.set(Calendar.MINUTE, minute); 
        calendar.set(Calendar.SECOND, second); 
        calendar.set(Calendar.MILLISECOND, 0); 
        
    	Date now = new Date();
    	if (calendar.getTime().before(now)) { 
            calendar.add(Calendar.DATE, 1); 
        }
    	
        return calendar.getTime().getTime() - now.getTime();
    }
    
    public static void main(String args[]){
		System.out.println(nextDelayTime(20 , 39, 0));
    }
}
